/*
 * Copyright (C) 2004-2006 nickyb@users.sourceforge.net
 * 
 * This file is part of FreeQueryBuilder (http://querybuilder.sourceforge.net)
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

package net.sourceforge.querybuilder;

import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

public class MainMenubar extends JMenuBar
{
	private MainWindow owner;
	
	public MainMenubar(MainWindow owner)
	{
		this.owner = owner;
		
		JMenu mFile = new JMenu("file");
		add(mFile);
		
		mFile.add(new ActionChangeConnection());
		mFile.addSeparator();
		mFile.add(new ActionExit());
		
		JMenu mQuery = new JMenu("query");
		add(mQuery);
		
		mQuery.add(owner.builder.getActionMap().get("copy-syntax"));
		mQuery.add(owner.builder.getActionMap().get("clear-diagram"));
		mQuery.addSeparator();
		mQuery.add(new JCheckBoxMenuItem(owner.builder.getActionMap().get("select-distinct")));
		mQuery.add(new JCheckBoxMenuItem(owner.builder.getActionMap().get("change-work-mode")));
		mQuery.addSeparator();
		mQuery.add(new ActionPreview());
	}

	private class ActionPreview extends AbstractAction
	{
		ActionPreview()
		{
			super("preview");
		}
		
		public void actionPerformed(ActionEvent e)
		{
			QueryBuilder builder = MainMenubar.this.owner.builder;
			QueryModel model = builder.getModelClone();
			
			if(builder.getConnection()!=null && model!=null)
				new QueryPreview(builder.getConnection(),model.getSyntax()).show();
		}
	}
	
	private class ActionChangeConnection extends AbstractAction
	{
		ActionChangeConnection()
		{
			super("change/open connection");
		}
		
		public void actionPerformed(ActionEvent e)
		{
			new MaskConnect(MainMenubar.this.owner).showDialog();
		}
	}
	
	private class ActionExit extends AbstractAction
	{
		ActionExit()
		{
			super("exit");
		}
		
		public void actionPerformed(ActionEvent e)
		{
			System.exit(0);
		}
	}
}